package com.ljc;

import java.util.Arrays;

/**
 * @author clj
 * @date 2022/8/22
 * @desc
 */
public class E27RemoveElement {
    public static void main(String[] args) {
        int[] nums = new int[] {0,1,2,2,3,0,4,2};
        int var = 2;
        int r = removeElement1(nums, var);
        System.out.println(r);
    }

    public static int removeElement(int[] nums, int var) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int point = 0;
        int[] rInts = new int[n];
        for (int num : nums) {
            if (num != var) {
                rInts[point] = num;
                ++point;
            }
        }
        System.out.println(Arrays.toString(rInts));
        return point;
    }

    public static int removeElement1(int[] nums, int val) {
        int n = nums.length;
        int left = 0;
        int[] rInts = new int[n];
        for (int right = 0; right < n; right++) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                rInts[left] = nums[right];
                left++;
            }
        }
        System.out.println(Arrays.toString(rInts));
        return left;
    }



}
